** label the values of your main DV (tapprover)
label define  tapprover -3 "strongly disapprove" -2 "slightly disapprove" -1 "disapprove" 3 "strongly dapprove" 2 "slightly approve" 1 "approve", replace
label values tapprover tapprover
tab tapprover

** label values of vote for variables
label define  voteforr 1 "Definitely Danny Tate" 2 "Leaning Danny Tate" 3 "Leaning Mike Williams" 4 "Definitely Mike Williams", replace
label values voteforr voteforr
tab voteforr

** apply the same label to (wapprover)
label values wapprover tapprover
tab wapprover

** create a binary version of tapprover and wapprover
gen tapprover_bin = tapprover
recode tapprover_bin -3=0 -2=0 -1=0 3=1 2=1 1=1
tab tapprover_bin tapprover

gen wapprover_bin = wapprover
recode wapprover_bin -3=0 -2=0 -1=0 3=1 2=1 1=1
tab wapprover_bin wapprover

** label the the values of new variables 
label define  tapprover_bin 0 "disapprove" 1 "approve"
label values tapprover_bin tapprover_bin
label values wapprover_bin tapprover_bin
tab tapprover_bin
tab wapprover_bin

** calculate the means of tapprover_bin by treatment group
mean tapprover_bin, over(group) coefleg
mean wtrustr_bin, over(group) coefleg

*test whether the mean in group 2 is different from group 3
test _b[c.tapprover_bin@2.group] = _b[c.tapprover_bin@3.group]
test _b[c.wtrustr_bin@2.group] = _b[c.wtrustr_bin@3.group]
test _b[c.voteforr_bin@1.group] = _b[c.voteforr_bin@3.group]
test _b[c.voteforr_bin@7.group] = _b[c.voteforr_bin@8.group]

** calculate mean the means of tapprover_bin by treatment group without COEFLEG so you can see the standard errors and confidence intervals
mean tapprover_bin, over(group)

*** encode a string variable and label it
encode teffective, gen(teffectivex)
tab teffectivex
tab teffectivex, nolabel
recode teffectivex 1=2 3=1 5=3 2=-2 4=-1 6=-3
tab teffectivex
label define  teffectivex -3 "very ineffective" -2 "ineffective" -1 "slightly ineffective" 3 "very effective" 2 "effective" 1 "slightly effective", replace
label values teffectivex teffectivex
tab teffectivex
tab teffectivex teffective

** Code for net values
gen w_approve_net = wapprover - tapprover
tab w_approve_net
mean w_approve_net, over(group) coeflegend
test  _b[c.w_approve_net@4.group] =  _b[c.w_approve_net@6.group]

gen w_approve_net_bin = w_approve_net
recode w_approve_net_bin -1=0 -2=0 -3=0 -4=0 -5=0 -6=0 0=. 1=1 2=1 3=1 4=1 5=1 6=1
tab w_approve_net_bin w_approve_net
mean w_approve_net_bin, over(group)

** test for significance
test  _b[c.w_effective_net_bin@1.group] =  _b[c.w_effective_net_bin@3.group]
test  _b[c.w_effective_net_bin@1.group] =  _b[c.w_effective_net_bin@2.group]
test  _b[c.w_effective_net_bin@2.group] =  _b[c.w_effective_net_bin@3.group]
test  _b[c.w_effective_net_bin@4.group] =  _b[c.w_effective_net_bin@6.group]
test  _b[c.w_effective_net_bin@4.group] =  _b[c.w_effective_net_bin@5.group]
test  _b[c.w_effective_net_bin@5.group] =  _b[c.w_effective_net_bin@6.group]
test  _b[c.w_effective_net_bin@7.group] =  _b[c.w_effective_net_bin@9.group]
test  _b[c.w_effective_net_bin@7.group] =  _b[c.w_effective_net_bin@8.group]
test  _b[c.w_effective_net_bin@8.group] =  _b[c.w_effective_net_bin@9.group]
test  _b[c.w_effective_net_bin@10.group] =  _b[c.w_effective_net_bin@12.group]
test  _b[c.w_effective_net_bin@10.group] =  _b[c.w_effective_net_bin@11.group]
test _b[c.w_effective_net_bin@11.group] =  _b[c.w_effective_net_bin@12.group]


test  _b[c.w_trust_net_bin@7.group] =  _b[c.w_trust_net_bin@9.group]


** relabel all variables
. label variable q6 "Sex"
. label variable q7 "State"
. label variable q8 "Marital status"
. label variable q9 "Education"
. label variable q10 "Ethnicity"
. label variable q11 "Race"
. label variable q12 "Year of birth"
. label variable q13 "Income"
. label variable q14 "Religion"
. label variable q15 "Religious service attendance"
. label variable q3 "Attention to politics"
. label variable q1 "Party ID"
. label variable q2 "Ind. leaner"
. label variable v33 "Rep. strength"
. label variable q16 "2016 primary vote"
. label variable q4 "Rep. party fav"
. label variable q5 "Dem. party fav"
. drop q301_firstclick
. drop q301_lastclick
. drop status progress durationinseconds finished recordeddate responseid recipientlastname recipientfirstname recipientemail externalreference locationlatitude locationlongitude distributionchannel userlanguage
. drop ipaddress
. drop q301_pagesubmit q301_clickcount q302_firstclick q302_lastclick q302_pagesubmit q302_clickcount q303_firstclick q303_lastclick q303_pagesubmit q303_clickcount q304_firstclick q304_lastclick q304_pagesubmit q304_clickcount q305_firstclick 305_lastclick q305_pagesubmit q305_clickcount q306_firstclick q306_lastclick q306_pagesubmit q306_clickcount q307_firstclick q307_lastclick q307_pagesubmit q307_clickcount q308_firstclick q308_lastclick q308_pagesubmit q308_clickcount q309_firstclick q309_lastclick q309_pagesubmit q309_clickcount q310_firstclick q310_lastclick q310_pagesubmit q310_clickcount q311_firstclick q311_lastclick q311_pagesubmit q311_clickcount q312_firstclick q312_lastclick q312_pagesubmit q312_clickcount
. label variable group4 "4 AC"
. label variable group4 "4 comp check"
. label variable group5 "5 comp check"
. label variable group6 "6 comp check"
. label variable group10 "10 comp check"
. label variable group11 "11 comp check"
. label variable group12 "12 comp check"
. label variable group1 "1 comp check"
. label variable group2 "2 comp check"
. label variable group3 "3 comp check"
. label variable group7 "7 comp check"
. label variable group8 "8 comp check"
. label variable group9 "9 comp check"
. label variable v67 "Dem. strength"
. label variable v68 "2020 primary vote"
. label variable tatetrue "Tate attack true"
. label variable tatetrue "Attack true?"
. label variable q36 "Qualitative"
. label variable q285 "Age (years)"

** Create nonpartisan groups
gen groupcharacclaim=(group==1 | group==4)
gen groupcharexplain=(group==2 | group==5)
gen groupcharattack=(group==3 | group==6)
gen grouppolacclaim=(group==7 | group==10)
gen grouppolexplain=(group==8 | group==11)
gen grouppolattack=(group==9 | group==12)

** Check nonpartisan group statistics
tab groupcharacclaim wapprover_bin
tab groupcharacclaim wtrustr_bin
tab groupcharacclaim weffectiver_bin
tab groupcharexplain wapprover_bin
tab groupcharexplain wtrustr_bin
tab groupcharexplain weffectiver_bin
tab groupcharattack wapprover_bin
tab groupcharattack wtrustr_bin
tab groupcharattack weffectiver_bin
tab grouppolacclaim wapprover_bin
tab grouppolacclaim wtrustr_bin
tab grouppolacclaim weffectiver_bin
tab grouppolexplain wapprover_bin
tab grouppolexplain wtrustr_bin
tab grouppolexplain weffectiver_bin
tab grouppolattack wapprover_bin
tab grouppolattack wtrustr_bin
tab grouppolattack weffectiver_bin
